package com.dc.flow.vm

import androidx.lifecycle.ViewModel
import com.dc.flow.state.LoadingState
import com.dc.flow.state.PageState
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow

open class BaseFlowViewModel : ViewModel() {

    private val _pageState = MutableStateFlow<PageState<String>>(PageState.ShowContent(""))
    val pageState = _pageState.asStateFlow()

    private val _loadingState = MutableStateFlow<LoadingState>(LoadingState.Hide())
    val loadingState = _loadingState.asStateFlow()

    fun changePageState(pageState: PageState<String>) {
        _pageState.value = pageState
    }

    fun changeLoadingState(isShowing: Boolean, tipsWord: String = "") {
        if (isShowing) showLoading(tipsWord) else dismissLoading()
    }

    private fun showLoading(tipsWord: String = "") {
        _loadingState.value = LoadingState.Show(tipsWord)
    }

    private fun dismissLoading() {
        _loadingState.value = LoadingState.Hide()
    }

}